package com.xw.common;


import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Description: TODO
 * @Author: 72478
 * @Date: 2024/12/20 09:10
 * @Version: 1.0
 */
@Getter
@AllArgsConstructor
public enum RoleEnum {

    ADMIN("ROLE_ADMIN", "管理员"),
    USER("ROLE_USER", "普通用户"),
    TEACHER("ROLE_TEACHER", "老师");

    private final String code;
    private final String desc;
    /**
     * 根据code获取desc
     * @param code
     * @return
     */
    public static String getDescByCode(String code) {
        for (RoleEnum role : RoleEnum.values()) {
            if (role.getCode().equalsIgnoreCase(code)) {
                return role.getDesc();
            }
        }
        return RoleEnum.TEACHER.getDesc();
    }

    public static String getCodeByDesc(String desc) {
        for (RoleEnum role : RoleEnum.values()) {
            if (role.getDesc().equalsIgnoreCase(desc)) {
                return role.getCode();
            }
        }
        return RoleEnum.TEACHER.getCode();
    }
}
